package chapter01

import (
	"fmt"
	"math"
)

func TestBoolean() {

	var v1 bool
	v1 = true
	v2 := (1 == 2)

	fmt.Println(v1)
	fmt.Println(v2)
}

func TestOp() {
	var intValueBit uint8
	intValueBit = 255
	intValueBit = ^intValueBit // 按位取反
	fmt.Println(intValueBit)   // 0
	intValueBit = 1
	intValueBit = intValueBit << 3 // 左移 3 位，相当于乘以 2^3 = 8
	fmt.Println(intValueBit)       // 8
}

func TestFloat() {
	var floatValue1 float32
	floatValue1 = 10
	floatValue2 := 10.0 // 如果不加小数点，floatValue2 会被推导为整型而不是浮点型
	floatValue3 := 1.1e-10

	fmt.Println(floatValue1)
	fmt.Println(floatValue2)
	fmt.Println(floatValue3)

	floatValue4 := 0.1
	floatValue5 := 0.7
	floatValue6 := floatValue5 + floatValue4
	fmt.Println(floatValue4)
	fmt.Println(floatValue5)
	fmt.Println(floatValue6)

	p := 0.00001
	if math.Dim(float64(floatValue1), floatValue2) < p {
		//浮点数相等近似判断
		fmt.Println("floatValue1 和 floatValue2 相等")
	}

}

func TestComplex() {
	var complexValue1 complex64

	complexValue1 = 1.10 + 10i
	complexValue2 := 1.10 + 10i

	complexValue3 := complex(1.10, 10)

	fmt.Println(complexValue1)
	fmt.Println(complexValue2)
	fmt.Println(complexValue3)

	fmt.Println(real(complexValue1))
	fmt.Println(imag(complexValue1))

}
